import ISJSBridge from './isJsBridge'

// 初始化JS API
const YMDD = {
  isAndroid: /android/i.test(navigator.userAgent),
  isIOS: /iphone|ipad|ios/i.test(navigator.userAgent),
  isYMDD: /YMDD/i.test(navigator.userAgent),
  version: '0.0.1',
  date: '2022-03-23'
}


// 以插件的形式提供给Vue

YMDD.install = function(Vue) {
  Vue.prototype.$YMDD = YMDD
}

/**
 * 获取用户个人信息
 **/

YMDD.getUserInfo = function(callback) {
  ISJSBridge.callApp('getUserInfo', null, callback)
}

/**
 * 获取个人设备信息
 **/

YMDD.getDeviceInfo = function(callback) {
  ISJSBridge.callApp('getDeviceInfo', null, callback)
}

/**
 * 关闭当前webView
 **/

YMDD.closeWebView = function(params) {
  ISJSBridge.callApp('closeWebView', params, null)
}

/**
 * 调用原生扫描
 *
 * @params.scanType 扫描类型
 * scanType = 1 基础扫描
 * scanType = 2 （未定义）
 * scanType = 3 装车扫描
 * scanType = 4 卸车扫描
 * scanType = 5 派件扫描
 **/

YMDD.nativeScan = function({
  scanType, isBatch, showInput,
  data = {}
}, callback) {
  const newScanType = '' + scanType
  ISJSBridge.callApp('nativeScan', {
    scanType: newScanType,
    isBatch: isBatch,
    showInput: showInput,
    data
  }, callback)
}



/**
 * 打电话
 * @params.phoneNum 电话号码
 */

YMDD.callPhone = function({
  phoneNum
}, callback) {
  const newPhone = '' + phoneNum
  ISJSBridge.callApp('callPhone', {
    phoneNum: newPhone
  }, callback)
}
YMDD.callPhoneItems = function({
  items,
  title
}, callback) {
  ISJSBridge.callApp('callPhoneItems', {
    items: items,
    title: title
  }, callback)
}

/**
 * 获取地理位置
 * longitude 经度
 * latitude, 纬度
 */

YMDD.getLocation = function(callback) {
  ISJSBridge.callApp('getLocation', null, callback)
}

/**
 * 打开手机通讯录
 * @param callback.data = {name:"",phone:""}
 */
YMDD.openPhoneBook = function(callback) {
  ISJSBridge.callApp('openPhoneBook', null, callback)
}


/**
 * 证件识别
 * @param params
 * @param callback: data{
    "ID_ADDRESS":"上海市青浦区徐泾镇徐祥路1108号",
    "ID_BIRT":"1995-12-31",
    "ID_FOLK":"汉",
    "ID_ISSUE":"",
    "ID_NAME":"张三",
    "ID_NUM":410425199204162050,
    "ID_SEX":"男",
    "ID_VALID":""
}
 */
YMDD.licenseSpot = function(params, callback) {
  ISJSBridge.callApp('licenseSpot', params, callback)
}

/**
 * 语音识别
 * @param params
 * @param callback
 */
YMDD.translateVoice = function(params, callback) {
  ISJSBridge.callApp('translateVoice', params, callback)
}

/**
 * 退出App(到登录界面)
 * @param params
 * @param callback
 */
YMDD.exitApp = function(params, callback) {
  ISJSBridge.callApp('exitApp', params, callback)
}

export default YMDD
